package com.dh.enum01;

public enum StatusCode {
    OK(200, "成功"),
    NOTFOUND(404, "没有找到资源"),
    NOPERMISSON(403, "无权限"),
    SERVERERROR(500, "服务器错误1");

    private int code;
    private String msg;

    StatusCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public static String GetMsg(int code) {
        // 继续比较
        StatusCode[] values = StatusCode.values();
        for (StatusCode value : values) {// 增强for循环
            if (code == value.code) {
                return value.msg;
            }
        }
        return "";
    }

    public static String GetMsg(StatusCode code) {
        // 继续比较
        StatusCode[] values = StatusCode.values();
        for (StatusCode value : values) {// 增强for循环
            if (value.equals(code)) {
                return value.msg;
            }
        }
        return "";
    }
}
